using System;
using Clandestine.Graphics;
using Clandestine.Graphics.Animation;

namespace Clandestine.Engines.Field
{
	
	public class TestMans : Entity
	{
		AnimatedSprite asp;
		int lastDir;
		
		
		#region implemented abstract members of Clandestine.Engines.Field.Entity
		public override void Step (TimeSpan delta, TimeSpan total)
		{
			int eggs = transultonatubular();
			//Console.WriteLine("TRANSULTON: " + eggs.ToString());
			
			if (eggs != lastDir)
			{
				if (eggs > 0)
					asp.Start( ((eggs & 1) == 1 ? "run_up" : ((eggs & 2) == 2 ? "run_down" : 
				           ((eggs & 4) == 4 ? "run_left" : ((eggs & 8) == 8 ? "run_right" : "") )  ) ) );
				else
					asp.Stop();
				
				//Console.WriteLine("BEES!");
				
				lastDir = eggs;
			}
			
			if (Logic.InputManager.IsButtonPressed(Buttons.Up))
				asp.Transform.Y--;
			else if (Logic.InputManager.IsButtonPressed(Buttons.Down))
				asp.Transform.Y++;
			if (Logic.InputManager.IsButtonPressed(Buttons.Left))
				asp.Transform.X--;
			else if (Logic.InputManager.IsButtonPressed(Buttons.Right))
				asp.Transform.X++;
		}
		
		#endregion
		
		
		private int transultonatubular()
		{
			int it = 0;
			if (Logic.InputManager.IsButtonPressed(Buttons.Up))
				it += 1;
			if (Logic.InputManager.IsButtonPressed(Buttons.Down))
				it += 2;
			if (Logic.InputManager.IsButtonPressed(Buttons.Left))
				it += 4;
			if (Logic.InputManager.IsButtonPressed(Buttons.Right))
				it += 8;
			return it;
		}
		
		public TestMans(Level level, Logic logic) : base(level, logic)
		{
			asp = new AnimatedSprite(this.PerpendicularRenderList, "spritesheets/npc/girl.png", "spritesheets/metadata/npc_32x48.xml");
			asp.Transform.X = 50;
			asp.Transform.Y = 50;
			asp.SetDepthAuto();
		}
	}
}

